Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use try_from_bytes in handle_file_urls #7652

Merged

Conversation

kazatsuyu
Copy link
Contributor

Reduce build error on Windows.

Release Notes:

  • N/A

@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Feb 10, 2024
@@ -131,7 +129,7 @@ impl OpenListener {
.flat_map(|url| url.strip_prefix("file://"))
.map(|url| {
let decoded = urlencoding::decode_binary(url.as_bytes());
PathBuf::from(OsStr::from_bytes(decoded.as_ref()))
PathBuf::try_from_bytes(decoded.as_ref()).unwrap()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: try_from_bytes always returns Ok on [cfg(unix)].

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because we don't control the input to this method, we should not panic if the bytes are invalid, but just ignore them. I think the following would be better:

Suggested change
PathBuf::try_from_bytes(decoded.as_ref()).unwrap()
.flat_map(|url| {
let decoded = urlencoding::decode_binary(url.as_bytes());
PathBuf::try_from_bytes(decoded.as_ref()).log_err()
})

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed this

@SomeoneToIgnore
Copy link
Contributor

SomeoneToIgnore commented Feb 10, 2024

I have no objections from merging that in if the reviewer finds it appropriate, but strongly urge you to consider adding Windows runners (GitHub seem to allow the standard ones: https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners/about-github-hosted-runners#using-a-github-hosted-runner so we can do smth. like #7581).
Without the CI, there's no guarantees that this won't degrade again, making the PR pointless in the long run.

I would not expect the code to 100% compile under Windows now, but some of the crates may be already?
If not, an effort could be made to make certain crate(s) to compile and add the Windows CI to check those first.

@ConradIrwin
Copy link
Member

@SomeoneToIgnore I think we've decided to wait on any big windows stuff until post linux; so let's not worry about CI.

@kazatsuyu Thanks for working on this. In general we should avoid unwrap'ing on errors, left a suggestion in line, but otherwise good to go.

@ConradIrwin ConradIrwin self-assigned this Feb 10, 2024
@ConradIrwin ConradIrwin merged commit 2880135 into zed-industries:main Feb 11, 2024
6 checks passed
@ConradIrwin
Copy link
Member

Thanks!

@kazatsuyu kazatsuyu deleted the windows-build-open_listener branch February 20, 2024 11:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla-signed The user has signed the Contributor License Agreement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants